#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Privilege-MA 安装配置文件
支持插件系统的entry_points机制
"""

from setuptools import setup, find_packages
import os

# 读取README文件
def read_readme():
    readme_path = os.path.join(os.path.dirname(__file__), 'README.md')
    if os.path.exists(readme_path):
        with open(readme_path, 'r', encoding='utf-8') as f:
            return f.read()
    return "Privilege-MA: Advanced Linux Privilege Escalation and Persistence Framework"

# 读取requirements文件
def read_requirements():
    req_path = os.path.join(os.path.dirname(__file__), 'requirements.txt')
    if os.path.exists(req_path):
        with open(req_path, 'r', encoding='utf-8') as f:
            return [line.strip() for line in f if line.strip() and not line.startswith('#')]
    return [
        'requests>=2.25.0',
        'cryptography>=3.4.0',
        'psutil>=5.8.0',
        'pycryptodome>=3.10.0',
        'colorama>=0.4.4',
        'tabulate>=0.8.9',
        'python-dateutil>=2.8.0',
        'packaging>=20.0'
    ]

# 版本信息
VERSION = "1.0.0"

setup(
    name="privilege-ma",
    version=VERSION,
    description="Advanced Linux Privilege Escalation and Persistence Framework",
    long_description=read_readme(),
    long_description_content_type="text/markdown",
    author="Privilege-MA Team",
    author_email="dev@privilege-ma.com",
    url="https://github.com/privilege-ma/privilege-ma",
    license="MIT",
    
    # 包配置
    packages=find_packages(),
    include_package_data=True,
    zip_safe=False,
    
    # Python版本要求
    python_requires=">=3.7",
    
    # 依赖包
    install_requires=read_requirements(),
    
    # 可选依赖
    extras_require={
        'dev': [
            'pytest>=6.0.0',
            'pytest-cov>=2.10.0',
            'black>=21.0.0',
            'flake8>=3.8.0',
            'mypy>=0.800',
            'sphinx>=3.5.0',
            'sphinx-rtd-theme>=0.5.0'
        ],
        'c2': [
            'dnspython>=2.1.0',
            'scapy>=2.4.0',
            'pycrypto>=2.6.0'
        ],
        'tools': [
            'paramiko>=2.7.0',
            'fabric>=2.6.0',
            'ansible>=4.0.0'
        ]
    },
    
    # 入口点配置 - 支持插件系统
    entry_points={
        # 主程序入口
        'console_scripts': [
            'privilege-ma=modules.main:main',
            'pma=modules.main:main',
        ],
        
        # 插件入口点 - 核心插件
        'privilege_ma.plugins': [
            # 权限提升插件
            'sudo_exploit=modules.plugins.examples.sudo_exploit:SudoExploitPlugin',
            'suid_scanner=modules.plugins.examples.suid_scanner:SuidScannerPlugin',
            'kernel_exploit=modules.plugins.examples.kernel_exploit:KernelExploitPlugin',
            
            # 权限维持插件
            'cron_persistence=modules.plugins.examples.cron_persistence:CronPersistencePlugin',
            'service_persistence=modules.plugins.examples.service_persistence:ServicePersistencePlugin',
            'ssh_backdoor=modules.plugins.examples.ssh_backdoor:SshBackdoorPlugin',
            
            # 规避检测插件
            'process_hiding=modules.plugins.examples.process_hiding:ProcessHidingPlugin',
            'log_cleaner=modules.plugins.examples.log_cleaner:LogCleanerPlugin',
            'rootkit_installer=modules.plugins.examples.rootkit_installer:RootkitInstallerPlugin',
            
            # 数据收集插件
            'credential_harvester=modules.plugins.examples.credential_harvester:CredentialHarvesterPlugin',
            'system_info_collector=modules.plugins.examples.system_info_collector:SystemInfoCollectorPlugin',
            'network_scanner=modules.plugins.examples.network_scanner:NetworkScannerPlugin',
            
            # 通信插件
            'reverse_shell=modules.plugins.examples.reverse_shell:ReverseShellPlugin',
            'dns_tunnel=modules.plugins.examples.dns_tunnel:DnsTunnelPlugin',
            'http_beacon=modules.plugins.examples.http_beacon:HttpBeaconPlugin',
        ],
        
        # C2协议插件
        'privilege_ma.c2_protocols': [
            'cobalt_strike=modules.communication.protocols.cobalt_strike:CobaltStrikeProtocol',
            'metasploit=modules.communication.protocols.metasploit:MetasploitProtocol',
            'custom_http=modules.communication.protocols.custom_http:CustomHttpProtocol',
            'dns_tunnel=modules.communication.protocols.dns_tunnel:DnsTunnelProtocol',
        ],
        
        # 外部工具插件
        'privilege_ma.external_tools': [
            'linpeas=modules.utils.tools.linpeas:LinPEASTool',
            'linenum=modules.utils.tools.linenum:LinEnumTool',
            'pspy=modules.utils.tools.pspy:PspyTool',
            'gtfobins=modules.utils.tools.gtfobins:GTFOBinsTool',
        ],
        
        # 规避策略插件
        'privilege_ma.evasion_strategies': [
            'anti_debug=modules.evasion.strategies.anti_debug:AntiDebugStrategy',
            'anti_vm=modules.evasion.strategies.anti_vm:AntiVMStrategy',
            'process_injection=modules.evasion.strategies.process_injection:ProcessInjectionStrategy',
            'memory_encryption=modules.evasion.strategies.memory_encryption:MemoryEncryptionStrategy',
        ]
    },
    
    # 包数据
    package_data={
        'modules': [
            'data/*',
            'templates/*',
            'configs/*',
            'plugins/examples/*',
        ],
    },
    
    # 分类信息
    classifiers=[
        "Development Status :: 4 - Beta",
        "Intended Audience :: Information Technology",
        "Intended Audience :: System Administrators",
        "License :: OSI Approved :: MIT License",
        "Operating System :: POSIX :: Linux",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
        "Programming Language :: Python :: 3.10",
        "Programming Language :: Python :: 3.11",
        "Topic :: Security",
        "Topic :: System :: Systems Administration",
        "Topic :: Software Development :: Testing",
    ],
    
    # 关键词
    keywords="privilege escalation, persistence, linux, security, penetration testing, red team",
    
    # 项目URLs
    project_urls={
        "Bug Reports": "https://github.com/privilege-ma/privilege-ma/issues",
        "Source": "https://github.com/privilege-ma/privilege-ma",
        "Documentation": "https://privilege-ma.readthedocs.io/",
        "Changelog": "https://github.com/privilege-ma/privilege-ma/blob/main/CHANGELOG.md",
    },
)